package com.ace3l.legal.backend.domain;

import javax.persistence.*;
import java.util.*;

/**
 * ACE3L.COM
 * com.ace3l.manager.domain
 * This code was written by Synesthesia Consulting Services in conjunction
 * with Ace3L.com. This code is confidential and proprietary. This code is
 * copyright (C) 2008  Synesthesia Consulting Services and Ace3L.com
 * Created By: ageer
 * Date: Jun 22, 2008
 * Time: 9:28:40 PM
 */
@Entity
@Table(name = "PROJECT")
@org.hibernate.annotations.GenericGenerator(
    name = "hibernate-increment",
    strategy = "increment"
)
@NamedQueries({
    @NamedQuery(name="projects.byid",query="from Project p where p.lawFirm.id = ?"),
    @NamedQuery(name="projects.byid.abridged",query="select title, description, id, hoursAllotted, hoursCompleted, workflowStage, dueDate from Project p where p.lawFirm.id = :lawFirmId"),
    @NamedQuery(name="projects.bystatus.abridged",query="select id, title, hoursAllotted, dueDate, lawFirm.lawFirmName from Project p where p.workflowStage = :status"),
    @NamedQuery(name="projects.bystatus",query="from Project p where p.workflowStage = :status"),
    @NamedQuery(name="project.byid",query="from Project p where p.id = :projectId")
})
public class Project {
    @Transient
    public static Project EMPTY_PROJECT = new Project();

    @Id @GeneratedValue(generator = "hibernate-increment")
    @Column(name = "PROJECT_ID")
    private Integer id;
    private String title;
    private String description;
    
    @Temporal(value = TemporalType.DATE)
    private Date dueDate;

    @ManyToOne
    @JoinColumn(name = "LAWFIRM_ID")
    private LawFirm lawFirm;

    private Integer hoursAllotted;
    private Integer hoursCompleted;
    
    @OneToMany (fetch = FetchType.EAGER)
    @JoinTable(name="PROJECT_ASSIGNEDSTUDENTS",
        joinColumns = @JoinColumn(name="PROJECT_ID"),
        inverseJoinColumns = @JoinColumn(name="STUDENT_ID")
    )
    private Set<Student> assignedStudents = new HashSet();
    private String workflowStage;
//    private List workflowEvents = new ArrayList();
    
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Date getDueDate() {
        return dueDate;
    }

    public void setDueDate(Date dueDate) {
        this.dueDate = dueDate;
    }

    public LawFirm getLawFirm() {
        return lawFirm;
    }

    public void setLawFirm(LawFirm lawFirm) {
        this.lawFirm = lawFirm;
    }

    public Integer getHoursAllotted() {
        return hoursAllotted;
    }

    public void setHoursAllotted(Integer hoursAllotted) {
        this.hoursAllotted = hoursAllotted;
    }

    public Integer getHoursCompleted() {
        return hoursCompleted;
    }

    public void setHoursCompleted(Integer hoursCompleted) {
        this.hoursCompleted = hoursCompleted;
    }

    public Set<Student> getAssignedStudents() {
        return assignedStudents;
    }

    public void setAssignedStudents(Set<Student> assignedStudents) {
        this.assignedStudents = assignedStudents;
    }

    public void addAssignedStudent(Student s) {
        assignedStudents.add(s);
    }

    public String getWorkflowStage() {
        return workflowStage;
    }

    public void setWorkflowStage(String workflowStage) {
        this.workflowStage = workflowStage;
    }


//    public List getWorkflowEvents() {
//        return this.workflowEvents;
//    }
//
//    public void setWorkflowEvents(List workflowEvents) {
//        this.workflowEvents = workflowEvents;
//    }
//
//    public void addWorkflowEvent(WorkflowEvent w) {
//        w.setIndexId(workflowEvents.size());
//        w.setProject(this);
//        workflowEvents.add(w);
//    }
}
